Need some assistance with coding. I currently have a motion sensor music box that when activated cranks an old music machine. The code and the Electonics work great! here is the code that works
const int pirPin = 3;
const int motorPin = 2;
int switchState = 0;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(motorPin, OUTPUT);
pinMode(pirPin, INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
switchState = digitalRead(pirPin);
if (switchState == HIGH) {
digitalWrite(motorPin, HIGH);
}
else {
digitalWrite(motorPin, LOW);
}
}
The issue I am having is that I wanted to add a secondary switch for touch / electromagnetic but when I upload the new code for it, the motor will not spin with motion and just continuously spins when the other sensor is in slot 4. I am just checking to see if my coding is wrong and to see what I can do to have 2 sensors hooked up to trigger the motor. Here is the new code I am trying to get to work.
#include <CapacitiveSensor.h> // Import capaitivesenosr library
CapacitiveSensor cs_4 = CapacitiveSensor(5,4); // 1M resistor between pins 2 & 4, pin 4 is sensor pin, add a wire and
const int pirPin = 3;
const int motorPin = 2;
int switchState = 0;
int in = 5;
int out = 4;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(motorPin, OUTPUT);
pinMode(pirPin, INPUT);
pinMode(4, INPUT);
}
// the loop routine runs over and over again forever:
void loop()
{
switchState = digitalRead(pirPin);
switchState = digitalRead(4);
if (switchState == HIGH) {
digitalWrite(motorPin, HIGH);
}
else {
digitalWrite(motorPin, LOW);
}
}
You have labeled the component connected to pin 4 tmp, what is this, capacitive sensor ? It is not temp but the touch sensor I have has three prongs and I couldn't find that kind of sensor on tinkercad. Below is a picture of the sensor.
Does this work by itself ? I use the sensor on other projects but it needs a host.
What is the MOSFET part number ? L7805CV
What kind of battery are you using, PP3 ? Yes 2 of them. Originally had only one but it would die after 2 hours I added one to the board where the plug us and then the other to the breadboard where the second one is positioned. Now it last 6.5 hours
L7805CV is not a MOSFET, it is a 5V linear regulator, why are you using it?
Can you post some images of your project?
So we can see your component layout.
PLEASE.
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.
It is a custom of this forum that solutions be posted so as to be of a help to others with similar problems or requirements.