I used the standard relay plan using a diode, transister (TIP120) and uno.
The circuit worked fine with duemilanove, but when I tried it with uno it does not work right. Circuit stays on.
Can some one tell me what the difference between the two.
I used the standard relay plan using a diode, transister (TIP120) and uno.
The circuit worked fine with duemilanove, but when I tried it with uno it does not work right. Circuit stays on.
Can some one tell me what the difference between the two.
There is no difference that would effect controlling a relay from an output pin. You must have some other problem with the wiring or the coding.
Lefty
thank you.
Lefty if you are still here.
it is wire the same as duem, but the uno wont work.
here is the code:
const int ledPin = 7;
const int Sensor = 1;
const int threshold = 1;
int sensorReading = 0;
int pin7 = LOW;
void setup() {
pinMode(7, OUTPUT);
}
void loop() {
sensorReading = analogRead(Sensor);
if (sensorReading >= threshold) {
pin7 = !pin7;
digitalWrite(7, pin7);
delay(1000);
digitalWrite(7, LOW);
}
}
The logic in your code looks a bit strange. As far as I can see, on the 'odd' sensor activations the output will flash high for a second, on the 'even' activations it won't do anything. Is that what you intended?
Is (!HIGH) equal to LOW and vice-versa? It might be, but to me that looks like a dodgy thing to do. If you're using pin7 as a state variable I'd prefer to see it given a more meaningful name and explicitly used as a boolean, then when you want to output HIGH or LOW you can use the ternary operator to convert your true/false into HIGH/LOW.
Where is your sensor input defined? Have you initialised the sensor? Have you confirmed that the sensor input is returning sensible values and your threshold comparison is doing what you intended?
I am a newbie,
I am trying to control a relay with a piezo sensor. When the sensor detects a vibration it triggers the relay. It worked with the duem board but not the uno.But now I know why it only detects everyother hit.
If you want it to trigger on every hit, get rid of all the logic associated with pin7 and just explicitly change the output to High and then Low.
I'd still start by checking whether your sensor input is giving you the values you expect and whether your threshold check is being passed when you generate your input. The rest of the logic isn't quite right but will do something. There isn't much initialisation there, and you may be relying on defaults which are not identical between the different Arduino implementations.
I can not even get to the sensor part. as soon as I plug in the power the relay starts going like it is the blink program. I just dont know why it works with the older board. I really need help here. I am trying to make an interactive target for soldiers. When the sensor determines that the target is hit the relay triggers a soleniod that drops the target.
This may be a dumb question, but are you sure it's actually running your code? Maybe you haven't downloaded it successfully and you are still running whatever was on the chip when you got it. If you're using the standard IDE you need to select the right type of Arduino so that the bootloader works.
Here's another shot in the dark. After the sketch is loaded into the board, take a 10uf capacitor and connect the +side to the reset pin and the - side to ground. Press the reset button and see if it starts working. You'll need to remove the capacitor if you need to reload the sketch.
Thanx everyone. I will try these things in the morning.