is there an example or project done.. 2 Serveos powered by 2 Toggle Switchs

so i got the arduino software installed posted the code.. and ran the verify complie that works

nwo i trying to find where the images are like the tinkercad so i can draw it.. or can i import tinkercad drwawing
into arduno IDE

If you are going to give inputs names, which is a good idea, why not name them for the function that they perform rather than anonymous names like switch1 rather than fuelSwitch, for instance ?

It will not make the program work any better but it sure will make it easier to read and follow

ya i wasnt finished yet its just how i started it..
the rest you can see is labled ok
like Fuel start Fuel stop etc
i wasnt perfecting yet was trying to find out why its twitching the servo

and i trying to find how to add the graphics in arduino IDE as so far cant do it yet...
and clicking Sketch Folder just goes to my folder.. so i googling how to use the arduino IDE to get those graphics like the tinkercad but ill change the switchs now then
for now thats also why i had it remmed in the description but ill change it now

so i updated the code

//by mike nov 9 2020
//

#include <Servo.h>

//set the init values
Servo fuelservo,chokeservo;
//int angle,anglestart=0,fuelstart =0,chokestart =1,chokeangle;
//int angle
//the purpose of the chokeswitcha and fuelswitcha 
//is if i have a LOW if statement. its is continously
//running that code when it should be idle.
//so hopefully it it doesnt keep the proccessor running endless
//loop checking the LOW.. but instead only waits till there is 
//a HIGH detected

int chokestart = 20;			//Choke Postion When In Run Position  
int fuelstart = 20;  		// Fuel Postion When Off For Servo
int chokestop = 180;		// Postion to Stop Choke Servo
int fuelstop = 90;			// Postion to Stop Fuel Servo
int fuelangle=0,chokeangle=0;	// incremental postion for fuel choke servo
bool fuelswitch,fuelswitcha,chokeswitch,chokeswitcha;
  
void setup()
{
//set the pins for the 2 servos
  fuelservo.attach(9);
  chokeservo.attach(10);
  
//set the pins for the switchs
  pinMode(A0, INPUT_PULLUP);
  pinMode(A1, INPUT_PULLUP);
  pinMode(A2, INPUT_PULLUP);
  pinMode(A3, INPUT_PULLUP);

//set the switchs valve to low to initial setting  
  fuelswitch == LOW;
  chokeswitch == LOW;
  fuelswitcha == LOW;
  chokeswitcha == LOW;

}

void loop()
{
//read the valvue of the 2 pins  Low or High
fuelswitch = digitalRead(A0);
chokeswitch = digitalRead(A1);
fuelswitcha = digitalRead(A2);
chokeswitcha = digitalRead(A3);  

  
//Switch (Open The Fuel Valve)  
if(!fuelswitch == HIGH){
//switch1a == LOW;
	fuelangle = fuelangle +1;
	if (fuelangle > fuelstart){fuelangle = fuelstop;}
		fuelservo.write(fuelangle);
		delay(10);}

//Switch (Close the Fuel Valve)  
//if(!switch1 == LOW){
if(!fuelswitcha == HIGH){
//switch1 == LOW;
	fuelangle = fuelangle -1;
	if (fuelangle < fuelstart){fuelangle = fuelstart;}
		fuelservo.write(fuelangle);
		delay(10);}  
  
//Switch (Set Choke to the Choke Pos)  
if(!chokeswitch == HIGH){
//switch2a ==LOW;
	chokeangle = chokeangle +1;
  	if (chokeangle > chokestart){chokeangle = chokestop;}
		chokeservo.write(chokeangle);
//		delay(10000);}  
  		delay(10);}  

//Switch (Reset Choke Back to Run Pos)
 if(!chokeswitcha == HIGH){
// if(!switch2 == LOW){
//   switch2 == LOW;
	chokeangle = chokeangle -10;
	if (chokeangle < chokestart){chokeangle = chokestart;}
		chokeservo.write(chokeangle);
		delay(10);}  
  
  
}

using variables of type bool for reading input-pins is a bit weird.
usually you read the value of IO-pins into a byte or and int.

Your switch-wiring uses doubled wiring. It is sufficient to have one pin of your switch connected to ground and only one pin connected to an input-pin.

Through configuring the IO-pin as INPUT_PULLUP this means

if nothing is connected to the IO-pin the IO-pin has logic-level HIGH through the internal Pull-up-resistor.
If the switch is in that position that makes contact between the IO-pin and ground this closed contact pulls the logic-level down to LOW.

Why would you want to code this

  if (fuelangle > fuelstart) {
    fuelangle = fuelstop;
  }
  fuelservo.write(fuelangle);

as soon as fuelangle becomes bigger than 20 set fuelangle to 180
This counteracts on increment fuelangle step by step through +1

You should give your variables self-explaining names
switch1 says nothing about the function of this switch1

A name like "FuelSwitch" would explain what the switch is doing in your code if the switch is closed

To make it even easier to read the code define constants about the two positions of the switch

#define CloseFuelValve LOW
#define OpenFuelValve HIGH

so an if-condition would be

if (FuelSwitch == OpenFuelValve)

the code explains itself without any additional comment

best regards Stefan

so you replied after my code modifcations and i mentioned the reason it was called switch1 switch2 is just how i started and wasnt done… and i mentioned i modified i code i found alternted it

the reason i added the 3rd wire to each switch is what i mentioned.
if switch 1 is low that loops keeps running endless
so if you have 2 HIGHs for 1 switch it will only run when it detects a HIGH and not continous run when there is a LOW
as i said that should free up the processor… instead of running the LOW routine endlessly least thats my thinking
as you seen i had if Switch=LOW in the remmed statesments
and that didnt remove the twitch and figured its also contanstaly checking LOW state

as for the if (fuelangle > fuelstart) command i learned
that the fuel angle is the increments of 1 and thats how i used the example they used started at 0 and ended at 90

so it was orginal code was for 1 servo… and the guy used 2 buttons

// Last Mod. 02/aug/19  by Roy Erick

#include <Servo.h>
Servo motor;
int angle = 90;
bool button1,button2;
  
void setup()
{
  motor.attach(9);
  pinMode(A0, INPUT_PULLUP);
  pinMode(A1, INPUT_PULLUP);
}

void loop()
{
button1 = digitalRead(A0);
button2 = digitalRead(A1);

if(!button1 == HIGH){
angle = angle +1;
  if (angle > 180){angle = 180;}  
motor.write(angle);
delay(10);}
  
  
if(!button2 == HIGH){
angle = angle -1;
  if (angle < 0){angle = 0;}  
motor.write(angle);
delay(10);}  
  
  
}

so i adapted to it…
so where did i go wrong
fuelangle is the postion of the Servo incremented by 1
fuelstop is dont turn farther then the given number
fuelstart is where to start the servo… but i used to have 0 but like i mentioned i been playing numbers
as its twitching

but ill re read what you wrote… and still cant find how you draw this in arduino IDE yet they have pictures in the example folders

just thinking i guess doesnt matter… its always checking the HIGH To all the time
ill change to code and drawing

so to get things straight the reason i added

 if(!fuelswitch == HIGH){
	fuelangle = fuelangle +1;
	if (fuelangle > fuelstart){fuelangle = fuelstop;}
		fuelservo.write(fuelangle);
		delay(10);}

is you want the fuel servo to incriminate at a certain speed then when it fuel angle = 90 degrees it stops… so its incriminting at 1 degree at a time… least thats how i reading this as
i reading is as if current postion of the fuel servo is greater then 0 keep sending to the fuelservo.write untill {fuelangle = fuelsetop} then dont do anymore

is that how its to sound… End IF a Do While Loop?

and here i cleaned up the coding didnt add the define stuff i need to read more on if states as i used to Visual Basic If states and they both different

and why does x=x+1 go a certain speed but a x=x-1 doesnt go the same rate… to equal x=x+1 i had to go x=x-10

i still learning this code bear with me… always learning (:

//by mike nov 9 2020
//

#include <Servo.h>

//set the init values
Servo fuelservo,chokeservo;

int chokestart = 0;			//Choke Postion When In Run Position  
int fuelstart = 0;  		// Fuel Postion When Off For Servo
int chokestop = 180;		// Postion to Stop Choke Servo
int fuelstop = 90;			// Postion to Stop Fuel Servo
int fuelangle=0,chokeangle=0;	// incremental postion for fuel choke servo
bool fuelswitch,chokeswitch;
  
void setup()
{
//set the pins for the 2 servos
  fuelservo.attach(9);
  chokeservo.attach(10);
  
//set the pins for the switchs
  pinMode(A0, INPUT_PULLUP);
  pinMode(A1, INPUT_PULLUP);

//set the switchs valve to low to initial setting  
//  fuelswitch == LOW;
//  chokeswitch == LOW;

}

void loop()
{
//read the valvue of the 2 pins  Low or High
fuelswitch = digitalRead(A0);
chokeswitch = digitalRead(A1);

  
//Switch (Open The Fuel Valve)  
if(!fuelswitch == HIGH){
	fuelangle = fuelangle +1;
	if (fuelangle > fuelstart){fuelangle = fuelstop;}
		fuelservo.write(fuelangle);
		delay(10);}

//Switch (Close the Fuel Valve)  
if(!fuelswitch == LOW){
	fuelangle = fuelangle -1;
	if (fuelangle < fuelstart){fuelangle = fuelstart;}
		fuelservo.write(fuelangle);
		delay(10);}  
  
//Switch (Set Choke to the Choke Pos)  
if(!chokeswitch == HIGH){
	chokeangle = chokeangle +1;
  	if (chokeangle > chokestart){chokeangle = chokestop;}
		chokeservo.write(chokeangle);
//		delay(10000);}  
  		delay(10);}  

//Switch (Reset Choke Back to Run Pos)
 if(!chokeswitch == LOW){
	chokeangle = chokeangle -10;
	if (chokeangle < chokestart){chokeangle = chokestart;}
		chokeservo.write(chokeangle);
		delay(10);}  
  
  
}

so i added the code define… i had to reverse the HIGH LOW i dunno why?
but is this all correct soo far… and i left that other if statements in there if i take it out it doesnt wanna move go figure lol
but the pupose is for the CHOKE IF statesments i didnt want it go pull the lever fast so i wanted it to do it incrmentaly so instead of say 1 second it pulled ot over 3 seconds thats the real reason for the if statements and the incremental counter

i think i did it properly now do i need to change that BOOL fuelswitch,chokeswitch to something else?

UPDATED::
ok i updated for the final time i think i did it ok… i still get the servo twich and i still cant find the visual side of ARDUNIO IDE for the simulator part so i can see this working and the servos still dont center at 0 they both off set

//by mike nov 9 2020
//

#include <Servo.h>

//set the init values
Servo fuelservo,chokeservo;

int chokestart = 0;			//Choke Postion When In Run Position  
int fuelopen = 90;  		// Fuel Postion When Off For Servo
int chokestop = 180;		// Postion to Stop Choke Servo
int fuelclosed = 0;			// Postion to Stop Fuel Servo
int fuelangle=0,chokeangle=0;	// incremental postion for fuel choke servo
bool fuelswitch,chokeswitch;
#define  CloseFuelValve HIGH
#define  OpenFuelValve LOW
#define  ChokeOpen LOW
#define  ChokeClose HIGH	

void setup()
{
//set the pins for the 2 servos
  fuelservo.attach(9);
  chokeservo.attach(10);
  
//set the pins for the switchs
  pinMode(A0, INPUT_PULLUP);
  pinMode(A1, INPUT_PULLUP);

}

void loop()
{
//read the valvue of the 2 pins  Low or High
fuelswitch = digitalRead(A0);
chokeswitch = digitalRead(A1);

  
//Switch (Open The Fuel Valve)
if (fuelswitch == OpenFuelValve){
  	fuelservo.write(fuelopen);
	delay(10);}

//Switch (Close the Fuel Valve)  
if (fuelswitch == CloseFuelValve) {
  	fuelservo.write(fuelclosed);
	delay(10);}

//Switch (Set Choke to the Choke Pos)  
if (chokeswitch == ChokeOpen) {
  	chokeangle = chokestop;
	chokeservo.write(chokestop);
//		delay(10000);}  
 	delay(10);}  

//Switch (Reset Choke Back to Run Pos)
if (chokeswitch == ChokeClose){ 
	chokeangle = chokeangle -1;
	if (chokeangle < chokestart){chokeangle = chokestart;}
		chokeservo.write(chokeangle);
  
  delay(10);}  
  
  
}

THe Arduino IDE has no simulator. This is a specialty of tinkercad with which AutoDesk wants to absorb as many users for their products as ever possible. Thow their CAD-Products Fusion is not the best and not the most productive CAD-Software on the market.

If tinkercad offers simulation you can use it. But at a certain point you have switch over to real hardware and face the real hardware-problems and solve them. A simulator can’t simulate voltage-reflections causing databuses to fail and it can’t simulate EMV or warming up of a real component causing temperature-drift.

So are you just testing in simulation or do you already have real components?

best regards Stefan

the only components i have servos from my radio controlled planes
i only thought of it and i seen the tinkercad so i figured i try
i know i tried last year a simulator was green like the Arduino IDE it complied then let you simulate
cant remember it

so i only been testing simulator to get it to try.. and then if it worked i was going to build it...

so far this seems to work... is there anything else i need to add using the real thing.. i changed the designe i figured i could use cat5e cable to run the 3 switchs and then a master power to the arduino on cat5E cable over a span of 50 feet.
to turn power on to the arduino 2 pair of wire.. the other 3 pairs be Start choke and fuel
and id have like a box with the arduino at the generator instead..
but how does the code look? how does it look so far.. it seems to work in the simulator.. anything that doesnt need to be in there? i found i needed to leave the Delay in there and if i change the delay in any of the sections it messes' the whole thing up.. you mentioned there is a way to beable to run more then 1 thing at a time as right now the way i see it you can do 1 thing at a time.. or if one takes too long it disables the rest of it... can i fix this code so it doesnt hang like that.. ... i figure i going to also order that intro kit for myself i posted to you earlier so i can get the arduino out of it..... in the picture the light bulb just represents the starter of the generator
i made do with what i had on the site.. oh and maybe if you had spare parts and an arduino you could bench test to see if this is working.. like it should be now
i just have to order an arduno off amazon later today then

//by mike nov 9 2020
//

#include <Servo.h>

//set the init values
Servo fuelservo,chokeservo;

int chokestart = 0;			//Choke Postion When In Run Position  
int fuelopen = 90;  		// Fuel Postion When Off For Servo
int chokestop = 180;		// Postion to Stop Choke Servo
int fuelclosed = 0;			// Postion to Stop Fuel Servo
int fuelangle=0,chokeangle=0;	// incremental postion for fuel choke servo
int startrelay =8;			//relay pin on the ardunio for starter
bool fuelswitch,chokeswitch,startbutton;
#define  CloseFuelValve HIGH
#define  OpenFuelValve LOW
#define  ChokeOpen LOW
#define  ChokeClose HIGH
#define	 StartButtonON HIGH
#define  StartButtonOFF LOW

void setup()
{
//set the pins for the 2 servos
  fuelservo.attach(9);
  chokeservo.attach(10);
  
//Set the pins for the starter relay  
 pinMode(startrelay, OUTPUT);
  //  starterrelay =   pinMode(8, OUTPUT);
  
//set the pins for the switchs
  pinMode(A0, INPUT_PULLUP);
  pinMode(A1, INPUT_PULLUP);
  pinMode(A2, INPUT_PULLUP);

}

void loop()
{
//read the valvue of the 2 pins  Low or High
fuelswitch = digitalRead(A0);
chokeswitch = digitalRead(A1);
startbutton = digitalRead(A2);

//What Startbutton is pressed Start Cranking  
  if (!startbutton == StartButtonON){
     digitalWrite(startrelay, StartButtonON);
    delay(10);
  }
  
//When Startbutton is released Stop Cranking  
  if (!startbutton == StartButtonOFF) {
    digitalWrite(startrelay, StartButtonOFF);
    delay(10);
  }
//Switch (Open The Fuel Valve)
if (fuelswitch == OpenFuelValve){
  	fuelservo.write(fuelopen);
	delay(10);}

//Switch (Close the Fuel Valve)  
if (fuelswitch == CloseFuelValve) {
  	fuelservo.write(fuelclosed);
	delay(10);}

//Switch (Set Choke to the Choke Pos)  
if (chokeswitch == ChokeOpen) {
  	chokeangle = chokestop;
	chokeservo.write(chokestop);
//		delay(10000);}  
 	delay(10);}  

//Switch (Reset Choke Back to Run Pos)
if (chokeswitch == ChokeClose){ 
	chokeangle = chokeangle -1;
	if (chokeangle < chokestart){chokeangle = chokestart;}
		chokeservo.write(chokeangle);
  
  delay(10);}  
  
  
}

doing mutliple things at the same time is using timing based on the function millis().

there are several tutorials explaining timing based on function millis()
most of them are high spohisticated. And indeed understanding how this works should not be the very first exercise about programming.

This one is pretty short but quite good unederstandable

longer because it uses videos and explains more details

Though I would just watch the free video and not buy access to all

best regards Stefan

Some comments on your code

 if (!startbutton == StartButtonOFF)

Code like this makes it difficult to read. Why not remove the negative and use

 if (startButtonState == PRESSED)

Now it reads more naturally and you can tell immediately that the button state is being tested to see whether it is on or off

    digitalWrite(startrelay, StartButtonOFF);

As above

    digitalWrite(startRelayPin, ON);

You can tell that a pin is being written to and that the relay is being turned on

    delay(10);

Why ?

Of course, the start button can only be pressed or not so you could do

if (startButtonState == PRESSED)
{
  digitalWrite(startRelayPin, ON);
}
else
{
  digitalWrite(startRelayPin, OFF);
}

You could be extra clever and use

digitalWrite(startRelayPin, digitalRead(startButtonPin));

and do it all in one statement but it is not so easy to read

ok ill get back to you later i have to re read al this.. with dislexi i gotta re read things 5 or more times.. and ill watch the videos
but thank you so far most appreciative

so i got that code incorporated but its working backwards can you see where i went wrong
i use pressed as high and ON as high and OFF is LOW

but it lights up but when i press the button it turns off the bulb so the LOW and HIGH are reversed… what did i type wrong
but that code sure did shorten up things i appreciate it… always nicer lesser code to do the same stuff

… actually what i noticed they all reversed, to activate i had to use LOW to close or intial setting is HIGH…
is there a way to change the ardunino to say LOW is high and high is LOW

or once i get ardunio it be reversed

//by mike nov 9 2020
//

#include <Servo.h>

//set the init values
Servo fuelservo,chokeservo;

int chokestart = 0;			//Choke Postion When In Run Position  
int fuelopen = 90;  		// Fuel Postion When Off For Servo
int chokestop = 180;		// Postion to Stop Choke Servo
int fuelclosed = 0;			// Postion to Stop Fuel Servo
int fuelangle=0,chokeangle=0;	// incremental postion for fuel choke servo
int startRelayPin =8;			//relay pin on the ardunio for starter
bool fuelswitch,chokeswitch,startbutton,startButtonState;
#define  CloseFuelValve HIGH	//Set Close Fuel Valve
#define  OpenFuelValve LOW		//Set Open Fuel Value
#define  ChokeOpen LOW			//Set Choke Open
#define  ChokeClose HIGH		//Set Choke Close 
#define  PRESSED HIGH			//Set Button Pressed to HIGH to Equal ON
#define  ON LOW				//Set ON State To HIGH For Start Relay
#define  OFF HIGH				//Set OFF STate To LOW for Start Relay
void setup()
{
//set the pins for the 2 servos
  fuelservo.attach(9);
  chokeservo.attach(10);
  
//Set the pins for the starter relay  
 pinMode(startRelayPin, OUTPUT);
  //  starterrelay =   pinMode(8, OUTPUT);
  
//set the pins for the switchs
  pinMode(A0, INPUT_PULLUP);
  pinMode(A1, INPUT_PULLUP);
  pinMode(A2, INPUT_PULLUP);

}

void loop()
{
//read the valvue of the 2 pins  Low or High
fuelswitch = digitalRead(A0);
chokeswitch = digitalRead(A1);
startbutton = digitalRead(A3);
startButtonState = digitalRead(A2);
 

//Startbutton is pressed Start Cranking else do nothing

if (startButtonState == PRESSED)
	{
  		digitalWrite(startRelayPin, ON);
	}
else
	{
  		digitalWrite(startRelayPin, OFF);
	}
  
//Switch (Open The Fuel Valve)
if (fuelswitch == OpenFuelValve){
  	fuelservo.write(fuelopen);
	delay(10);}

//Switch (Close the Fuel Valve)  
if (fuelswitch == CloseFuelValve) {
  	fuelservo.write(fuelclosed);
	delay(10);}

//Switch (Set Choke to the Choke Pos)  
if (chokeswitch == ChokeOpen) {
  	chokeangle = chokestop;
	chokeservo.write(chokestop);
//		delay(10000);}  
 	delay(10);}  

//Switch (Reset Choke Back to Run Pos)
if (chokeswitch == ChokeClose){ 
	chokeangle = chokeangle -1;
	if (chokeangle < chokestart){chokeangle = chokestart;}
		chokeservo.write(chokeangle);
  
  delay(10);}  
  
  
}

Generally, use of INPUT_PULLUP means that you wire your system to ensure that a button press will give you LOW.

oh ok so thats normal..
so if you wanted to have Button and a switch to go HIGH
would it be INPUT_PULLDOWN

is there specific purpose to do this reversing if possible etc

likes whats the benefits.. for it being LOW when pressed..
but then i did read that one article it shows the INPUT_PULLUP when you dont wanna use a resistor

but so far all of its working now i just need ardunio to test in real life

always learning something new everyday thats for sure!!!

so if you wanted to have Button and a switch to go HIGH
would it be INPUT_PULLDOWN

Most Arduino boards only have INPUT_PULLUP

You may find it easier to #define PRESSED as LOW (or ON as LOW if using an on/off switch rather than a pushbutton) to make the code easier to write and read

comet424:
oh ok so thats normal..
so if you wanted to have Button and a switch to go HIGH
would it be INPUT_PULLDOWN

No. If you want an internal resistor, INPUT_PULLUP is your only option. You can use external resistors if you insist on pulldowns though. It's easier to change code than wire up resistors. Especially when you have set yourself up with this:

#define  PRESSED HIGH			//Set Button Pressed to HIGH to Equal ON

Edit: too slow :slight_smile:

oh ok ya internal resistor is easiest..

no biggy to change it i changed the code LOW high to get it to work

so technally i could change my choke and fuel valve
to short code too as PRESSED as there is no difference from flipping a switch up or a button pressed... ill change. it as it seems easier the ON OFF PRESSED way

and is the UNO the one i wanna get.. right as i seen different models and the nano soooo small

i appreciate all the feed back.. i wish we had this stuff in 80s.. in the 80s i was coding on Commodore C64 and had that 200 in 1 radio shack electronics board to make things like a radio or a buzzer