Hi, I am currently making an arduino based switch for my raspberrypi which is currently being used as a print server for an older printer that I have. I am making this switch so that when the printer powers on it gives power (5 Volts from the printer's USB port) to the Arduino's D15 pin which then sends a power impulse to relay (on D5), making it send power to the raspberrypi's gpio pin for a second, simulating a button. My problem here is that when I send the 5V to the arduino's D15 port nothing happens.
Here is my code:
(Excuse me if it's not very good, I am a bit of a newbie).
< #define POWERPIN 15 #define RELAY 5
void setup() {
// put your setup code here, to run once:
pinMode(RELAY, OUTPUT);
pinMode(POWERPIN, INPUT);
Please follow the advice given in the link below when posting code. Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
And you can check your output & relay with the Blink Example
(Of course, change the code to match the I/O pins you're actually connected to.)
BTW - There's no need to duplicate your "logical code" in setup(). It looks like the default/resting state is low, so you can set the output low during setup().
You can also take-out the comments that that say - // put your setup code here, to run once: and // put your main code here, to run repeatedly: Those are notes to you before you start programming. Any comments should reflect what your code is actually doing..
By the way, sorry I haven’t posted the schematic yet, but I just realized I made a really stupid mistake in the hardware that might actually be the cause to why it isn’t working. Thank you @DVDdoug for the blink test recommendation and everyone else for your replies! If it still doesn’t work I’ll try the blink test and if after that it still doesn’t work I’ll let you know. FYI, I’m doing this tomorrow as it’s almost 23:00 and I need to sleep tonight as tomorrow I need to go to work. Thanks again everyone, Alex
The hardware issue that I mentioned yesterday was that I wired my transistor (the one controlling the relay) wrong. I managed to get the relay to click but my code still isn’t working. Thanks @anon73444976 for the pull-up tip, once again, I’ll look into it tomorrow. Thank you! Alex