Sounds good, just a couple questions. The toy side of your diagram shows 3 connections. The top goes to the 5v side of the switch, and the bottom to the other side of the switch? The 5v side of the switch branches off prior to the resistor, where is that going?
kennethlimcp, this is not a pull-to-ground situation situation since the voltage remains at about 5V even when the button is pressed. I suspect the resistor is to ground and the button pulls to 5V instead. So same idea with the SSR across the button. However, a transistor could be used as well. A PNP 2N3906 would do:
The resistor could be between 33K and 47K if I calculated right.
TheRick, the resistor on the diagram is internal to the toy and āassumedā to be there. So when the button is NOT pushed, the toy sees a ground (through the resistor). When the button is pushed, the toy sees +5V, with the resistor limiting the current that flows to ground.
I ordered the SSR that @AndyW suggested. So, hopefully I can incorporate that. Thanks so much everyone for all your help. Iām sure Iāll have more questions when the parts come in and I put everything together.
we are āmaking upā whatās on the Toy side and we assume that thereās like a normally high or according to @peekay123 a normally low switch and therefore a pull up/down resistor
Like you say just across the switch terminals will do cos the SSR acts like a switch to mimic the mechanical switch
Brilliant! I finally was able to test it today and it worked as advertised. Like @AndyW suggested I just connected the SSR across the switch terminals and now the Red Light turns on when switched to HIGH.
Thanks everyone for your help.
NEXT:
I actually located some source on github from someone who has also attempted this with arduino.
My next step is adapting the source to work with SparkCore. Iām sure Iāll have some questions about that as well once I get around to it.
I had a similar requirement for a parking assistant in my homeās garage. Basically, I needed a sensor (switch) to illuminate an LED for few seconds. I made a working unit originally with a 2n7000 FET a capacitor and a few resistors, which worked great until my kid decided to dismantle it! Plus, it would only extinguish the LED if the switch was open again, so I had to make a cam style trigger for that circuit.
Anyway, I had my Spark laying around, and quickly integrated the existing LED and switch. The Spark lives in a sealed kid proof box now! The switch connection is the basic arduino example, with the 10K resistor to ground on the sensor pin, D0 in my case. The switch also goes to D0 and 5V.
I hope this helps with your project in future. This has the added feature of not caring if the switch is still engaged, or if it was just a quick jab. Obviously wonāt help control it via wifi
void setup()
{
pinMode(7,OUTPUT); // LED output
pinMode(0,INPUT); // Button input
}
static unsigned char ledState = LOW;
static unsigned char buttonState = LOW;
static unsigned char lastButtonState = LOW;
static unsigned long ledCameOn = 0;
void loop()
{
// If the LED has been on for at least 5 seconds then turn it off,
// regardless of switch state (held in or released)
if(ledState == HIGH)
{
if(millis()-ledCameOn > 5000) // LED illuminates for 5 seconds.
{
digitalWrite(7,LOW);
ledState = LOW;
}
}
// If the button's state has changed, then turn the LED on IF it is not on already.
buttonState = digitalRead(0);
if(buttonState != lastButtonState)
{
lastButtonState = buttonState;
if((buttonState == HIGH) && (ledState == LOW))
{
digitalWrite(7,HIGH);
ledState = HIGH;
ledCameOn = millis();
}
}
}
Thanks for taking the time to post your code as this will help me with one of my projects where I did not know how to check state of button but, now I do ! Thanks, Very, Very Much
What resistance do I need to use on the spark core side to drive the SSR?
I am currently using the saintsmart 2 channel mechanical relay, it has 4 pins 1 VCC 1 GND 2 IN pins, how can I do the same when I am connecting the SSR? I noticed that the SSR has 2 input pins, 1VCC and 1 GND, so how and where could I add the IN pin(s) which will be connected to the Spark Core pins to set one of the Relays on my board to HIGH or LOW?
Last questionā¦ Can i also use the same SSR to switch 110V light (the specs says that Loan Currents up to 350V)?
Thank you for your help really appreciated.
Mustafa