i want to use arduino uno
and send 2 pwm signals (have read pin 5 and 6 are pwm signal 1khz)
and for the relay i can use pin 3, 9,10 and 11
i want to use the analogpin a0-a5
2 i wil use a potionmeter
and the orther 4 i use a push-to-make button (or a switch)
the aboven is progject 1.0
and for project 2.0 i like to wright a program that can give a pwm signal that goes change in duty
up and down, swipe between 80% and 60% back to 80% for example
i have 1 board whit 4 relays, on it, and 2x ims-1 motor driver
i know that i need for ims-1 a extra pin to enable the unit. but there fore i use a relay to do this,
the red led are going to a relay
and the blue led are going to pwm input
for the relay it on and off enough
for the orther i need a pwm signal
if you look to the code, it is more red and full whit errors than that it works
i am thinking to wright the code for every switch and test it, after that i can put 6 of the codes together
@pauls
no that is correct pwmign a relay does not make sense, thought it can also give on and off signal
but if that is not than i need to use 2,4,7 and 8 relay board
i need to use 2 analogpin for controlling the pwm output.
thought i can also use this for the relay, or is thit not possible??
Your switch wiring is wrong. You would need pull down resistors on A0-A3 to make that work. You get errors because you specified analog pins in lower case, like "a1".
int motor = 9;
int motor1 = 10;
int potentionmeter = A5;
int potentionmeter1 = A4;
int value;
int value1;
int motor_speed;
int motor_speed1;
void setup()
{
pinMode(motor, OUTPUT);
pinMode(motor1, OUTPUT);
pinMode(potentionmeter, INPUT);
pinMode(potentionmeter1, INPUT);
}
void loop()
{
value = analogRead(potentionmeter);
motor_speed = map(value,0,1023,1,254);
analogWrite(motor,motor_speed);
value1 = analogRead(potentionmeter1);
motor_speed1 = map(value1,0,1023,10,240);
analogWrite(motor1,motor_speed1);
}
on the aboven link you can see it works, in real life the pwm signal goes to ims-1 motordriver
next part is the relay function
but again void setup does again give errors. but why i don't know
int schak = 3;
int relay = 8;
void setup
{
pinMode(schak, INPUT);
pinMode(relay, OUTPUT);
}
void loop
{
value = analogRead(schak);
schaki = map(value,0,1023,10,240);
if (schaki>500) analogWrite(relay, HIGH);
else (relay, LOW);
}
error code
4:6: error: variable or field 'setup' declared void
6:24: error: expected '}' before ';' token
7:10: error: expected constructor, destructor, or type conversion before '(' token
8:1: error: expected declaration before '}' token
i know it needs more work
but i get already a error on void setup part
so i can't test it and see where the rest of the code does not function
i wanted to post the code in code tag, but didn't find it
but after looking again found it
int schak = 3;
int relay = 8;
void setup
{
pinMode(schak, INPUT);
pinMode(relay, OUTPUT);
}
void loop
{
value = analogRead(schak);
schaki = map(value,0,1023,10,240);
if (schaki>500) analogWrite(relay, HIGH);
else (relay, LOW);
}
in arduino pasting the code and get
sketch_jan02a:4: error: function definition does not declare parameters
sketch_jan02a:9: error: function definition does not declare parameters
int inPin = A3; // the number of the input pin
int outPin = 8; // the number of the output pin
int state = HIGH; // the current state of the output pin
int reading; // the current reading from the input pin
int previous = LOW; // the previous reading from the input pin
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
void setup()
{
pinMode(inPin, INPUT);
pinMode(outPin, OUTPUT);
}
void loop()
{
reading = digitalRead(inPin);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
digitalWrite(outPin, state);
previous = reading;
}
whit this i can set the relay on and pressing again set it to off
in the link it works on the simulator
need only to wright it for the orther 3 switches, after that i need to get everything in one code.
for the real live situation
i need a resistor on the switch side to gnd.
on the output goes to a relay board and to ims-1 motordriver, i believe i don't need to put resistors on it, becasue on that board is already done that.