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

hi i wanna do a project

that can handle 2 Servos.. by 2 Toggle Switchs

1 Switch when Turned to the On pos will fully rotate or maybe 90% say and then when you turn switch off goes back to 0 postion

  1. Switch number 2 when turned on Will only turn 1/4 or so.. and then turn back

and it all powered off a 12volt battery.. is this possible?? are there sample codes or projects done i could play with

Yes, there are switch examples that ship with the IDE, and the Servo library has example sketches.

oh ok and i new to the arduino i dont have one i played with different codes online.. is there a certain arduino i need?
and the IDE is the ardunio or what would i all need?

any arduino that has at least 4 IO-Pins will be able to do the job you have described.
2 IO-pins for the buttons two IO-pins for the 2 servos.
I guess you want to do more than just this. So an Arduino with some more IO-pins can be used.

If you really want to do just this project; two buttons and two servos make it work and never change anything.
this is a somehow small job.

Though you have to learn a few things about electronics. The microcontroller-world is not superstandardized like USB-devices. You have to take care of more details than just "does the plug fit into the socket"
it is not very much but even such a small project will fail if you don't know these details:

  • buttons need a pull-up or pull-down-resistor of an appropiate value to work reliable

  • servos need their own voltage-supply which can deliver enough current.
    the GND of the voltage-supply must be connected to GND of the microcontroller

  • be aware of electrostatic discharge and always do some precautions to avoid them
    If you shuffle across a carpet with plastic shoes you can become so electrostatically charged that a single touch of the microcontroller can destroy the microcontroller. Always discharge yourself by touching a metallic object connected to "earth" / "ground" like any electric device with a metallic housing and a three-wire-plug

best regards Stefan

@StefanL38
ah ok
ya what my project is to convert my current Generator which is manual to automatic

what i want it to do is
i use a 12Volt car battery that would power the generators starter and power the arduino and servos
there be a master power button that adds power to the arduino and servos and a button to start it but that wont need arduino

  1. Servo is to Turn the fuel supply on.
  2. Servo is to Pull The Choke to the Choke position and when its runing you flip the toggle switch and she goes to the Run postition... i cant afford 3000 dollar automatic generator but this 600 dollar one works but i wanted to make it simiple for my mother... as the generator is stationary

so i was going to just use Toggle Flip Switch not so much a button but i could use a button.. you need a resistor to know if its up or down i take it

and i going to put it all in a a steel box or a plastic box with those rubber seals..

i have a little experience in raspberry pi i made a small relay option so i coded a bit from examples and on certain times it flips a relay for me.. i found it easier then the arduino when i looked into things last year..
i guess arduino and raspberry pi both have pros and cons
and arduino is alot cheaper

Hi comet,

nice project. There you go. This is a pretty detailed description of what you want to do in the end.
Yes an arduino is cheaper and IMHO better suited to do this job.

Still some things to clear. You want to run the generator automatically and have the whole thing easy to use
by just pressing a button to start.

The final version of the program should takte care of most non-normal situations that can occur:

take a look into
motor does not start then your program should NOT try again and again and again to start the motor
there should be some kind of checking the battery-voltage and if battery-voltage sís too low stop trying to start
to avoid damaging the battery through too deep discharching

  • fuel tank is empty and motor stops or maybe even a gauge showing how much fuel is left

Some kind of feedback "motor is running" push choke back in after a certain time. How do you want to feed in this feedback into the microcontroller? Or what does the motor offer as possible feedback

Timing and the travelway of the servos have to be adpated. Which can only be done by you.
So learning some basics about programming would be a big advantage.

So do you have some programming experience?
Take a look into this tutorial

Arduino Programming Course
https://startingelectronics.org/software/arduino/learn-to-program-course/

It is easy to understand and a good mixture between writing about important concepts
and get you going in general.

When you learned to ride a bike. Did you start in a halfpipe trying do do backloop-jumps?
Surely not. It's the same thing with learning programming. Though it is not as dangerous as having a crash in a half-pipe.

You will moving up the learning-curve much faster if you take 3 or 4 hours time to work through this introductional tutorial.

If you start reading and think I know all this already. just write a first attempt how it could be coded.

As long as your postings show some own effort in driving up the learning curve you can ask as many questions as you like and you will get answers.

If you want somebody else to do 95% of the coding you probably will be redirected to the collabroation and gigs sub-forum.

Some more hints:
connecting switches and buttons: Gammon Forum : Electronics : Microprocessors : Switches tutorial

a basic example how to sweep a servo

there is another library controlledservo
with more functions than the other servo-library

usually the example work but are not explained in detail.
This means it is very common that newbees still have a lot of questions about the examples.

So take a look into these and if you have any concrete question about understanding a function in the sourcecode
post the whole sketch and ask our questions.

Again as your postings show some own effort in learning you can ask as much questions as you like and you will get help

best regards Stefan

i think i have a sketch good enough at the moment if i did correctly now id need ardunino and need help with the code but first see if i did correctly
i dunno if this work but i cant upload a photo it askes for http:// but dont have one here for a image just wanted to upload

but i put it on my onedrive
https://1drv.ms/u/s!AkZ74ugB21knsV7YzNsHXusmxNcE?e=35aZhW

Those applications you mention (flipping switches, pulling chokes) will likely require some sort of industrial servos, capable of a good deal of torque.

i had a reply ill have to post later.. power went out i lost what i typed.. ill reply later when power comes on.. as my modem wasnt on generator just battery backup and i lost my reply when i hit send..

i temp fixed it.. ill get back to you guys later with my detailed answers

i had a reply ill have to post later.. power went out i lost what i typed..

It should be in your drafts on the forum

ok so to try to remember what i wrote before..
ya i know a bit of programinng im of an ara that used to code in GWBasic and then Visual Basic.. i perfer Visual basic as i can draw the boxes how an app is supposed to look. in C++ or Python you gotta code the boxes i dont see a way to draw boxes text boxs etc on the screen.. so i never really practiced anythng farther then VB..

but i try a bit of pyton.. on my raspberry pie have couple small scripts turn on and off a relay from the app Crontab so nothing special..

but to comment i just skimmed it i have a headache so i not gonna look at webpages. i wanted to get my info out. i wrote earlier

soo.. it would be nice to make it start automatically but i dont know how to code it that it once running and automaticlly change the choke..

so i went with a basic design.. and use Servos as RC style and get the heavyduty version but dont need ones size for Robot Wars lol

but so the procedure i wanted to do is

1.. Flip toggle switch powers up 2 Servos , and Arduino.
2.. Flip the Toggle Switch turns the Fuel valve a 1/4 turn using a Servo
3.. Flip the Toggle Switch that pulls the leaver on the choke fully using a Servo
4. Press Start Button and fires up engine as long as it all works lol
5.. Flip Toggle Switch choke and the servo turns back to run pos..

and then once done.. i flip the Fuel toggle and turns the fuel off.. and then once it runs it out of gas i can then shut the power off and shut power switch/start switch for the generator run/stop

so basiclly that sums it .. and that they be in a box inside my home or shop and generator is outside.. so arduino can be at the Generator or in the box inside.. where i wannt start it..

Ridge makes a Generator like this with the cables and remote u can have inside but there generators too expensive lol.. but if i could also make it automatic it would adjust choke but i know i asking too much lol

as for the drafts.. i dont have a drafts just a Save Drafts.. so i unable to insert images in this message so not sure
but on my one drive i have 2 pics.. i did one that be like the box inside the home.. and 1 be the wiring schematic i came up with..

and this doesnt show the transfer switch where you manually switch like 6 breakers that you wanna have generator do as this isnt ment for hole house.. that kinda panel is 1000 bucks to switch over and well money is tight .. so i figured id try to do this
so any help be great.. but ill re read the posts with the links tommorow have a migraine.. and since i unable to post pics maybe you can take a pic an post it as i dont see a drafts option to upload images in the document here.. just Post preview and save draft but nothing to upload images.. as the upload images.. only says http:// well it be nice to be able to upload image under insert image..

but here is my OneDrive.. 2 files... and ill get back to you guys tomorrow (:

https://1drv.ms/u/s!AkZ74ugB21knsV7YzNsHXusmxNcE?e=35aZhW

as for the drafts.. i dont have a drafts just a Save Drafts..

Click on your Username top/right of the forum screen next to "My Posts". On the left of the page that opens you should have Show Drafts as a link

So here is your drawing inserted into a posting

For supplying standard-servos with 5V a resistor is not suitable. You must use a voltage-regulator.
Ohm's Law adjusted to your application and simplified down to two sentences:
A resistor has a constant value and the voltage would only fit for a certain current but the current is varying while the servo moves or just holds position. This means the voltage behind the resistor is varying and would damage the servo if the voltage is getting to high.

You should use a voltage-regulator that can deliver 5A. You will need to use big servos and they can draw easily a current of 2A per Servo. This voltage-regulator should be a DC-DC-step-down-regulator for high-efficiency.

An Arduino Nano works on 3.3V. It might be nescessary to have a voltage-levelshifter 3.3V to 5V for the servos.
If I remember right the Arduino-nano has a 5V input. So it could be connected to the DC-DC-Step-down-regulator too.

The starter-button could be replaced by a high-ampere-relay. Or a high-ampere MOS-FET An electrical starter for combustions-engines can draw up to 200A. In your case it will be less than that. Something between 10A and 40A. 10A is way too much for those standard-arduino-relay-kits. or "standard"-arduino-MOS-FET-shields. You have to get this information and the wiring has to have thick wires or stay with the manual start-button.

As far as what a Arduino can do controlling your generator is still a "piece of cake" for an arduino.
But you need to know quite a lot about electronics to make it work reliable. You will manage this with the help of the users here in the forum.

If you haven't a digital multimeter yet. This is the right time to buy one. A pretty simple one in the 20-30 dollar-range will do. If you like I can make some suggestions.

Some questions about security:
if the fuel-valve stays open for hours with the enginge not running. Will the fuel drop out or not?

if the choke stays pulled is the only consequence just using more fuel or can this damage the engine?

if the fuel-valve stays half open. Do you know how the engine reacts on that? too less fuel can make combustion engines overheat because the fuel has a cooling-effect through vaporising.

Does the running engine load the battery?

again: this project is really doable but you need more knowledge.
You can ask here in the forum for it.
best regards Stefan

ok 1.
i did the click my user name, and then show drafts... but it still doesnt let me insert a picture into these replies..
steflan was able to post my picture from my one drive.. but im unable to insert it.. the Show drafts only showed old articles i guess i asked but didnt post.. but no option to reply with images

now as the for generator its just a mobile generator dunno if i need heavy duty but probably.. .. the starter button is no probably as i can get that i just gonna wire to the generator or use a low powered switch and using a Relay as the 12 volt battery is beside the generator already..

so the fuel vavle already on the generator is a turner so you turn it 1/4 to open it and 1/4 to close it again doesnt leak or shouldnt.. if i could find a way to post pics other then OneDrive i would.. but the Insert Image you think be for posting pictures is for HTTP: and not local drive... frustrating but ill mange

as for the choke.. its just plastic lever.. the carburter and engine still good so you can go from CHOKED to Run and no need to worry about half way.. so
what you do is Flip the switch for Fuel it opens fully.. flip switch off and turns it closed
when you flip the choke switch it will pull the lever fully.. when you flip it off it will goto the Run pos..

i found i could do something on Tinkercad i dunno if you guys use it.. and it has a share i dunno if it works for you guys.. i played with it i cant find how to set the Servos to 0 when the power is off it goes 0 but when powered it off sets the servo cant keep it at 0 even with negative values... if u guys can see it.. i also added 18 volts to simulate 12 volts and googled the voltage regulator

but you mentioned people in here would know how to make it more adjustable the servo for the choke.. what would i have to ask... but so far i got this part working semi

if you can see it i dunno

oh and yes that generator charges the battery its a 7200/9000 watt champion generator so has a small battery but its not good so just gonna replace it or use a car battery and do you need heavy duty voltage regulators or 2 in parallel to handle high amperage servos as 1 5v voltage regulator cant handle too many amps right

what be cool to add if possible if the arduino could read a gauge you can add to gas tank to show how much fuel is left

i appreciate the help soo far
and hopefully i explained ok i have dyslexia so stuff sounds good in my head and i try to explain but doesnt always work

and an off topic question my one son that is 14 now is learning python on amazon there is arduino/raspberry kits is there one you guys recommend for a kid.. learning coding etc... and i even saw a Smart home kit ardunio setup

Hi G.,

inserting pictues is done through attaching them. If a picture is attached it will be inserted into the text automatically.
If you click on "preview" or "save draft" below the textwindow "Attachemnts and other options"
appear.

About leaking: imagine somebody is trying to start the generator and it does not start or the Arduino-code has a bug leaving fuel opened or half opened for hours. There shouldn't drop out fuel as dropping out fuel four hours would create a dangerous situation. Especially when trying to start again and a relay is too small for the big current creating sparks to set all on fire. The propability that this happens is very low but any insurance won't pay if they find out you used a device that has not passed safety tests. So you have to put effort into it to make it as safe as possible. Relays not used on the current-limit but with maximum 2/3 of the current limit, Same with diameter of wires. Look at the wire-diamater of the wires supplying the electric-starter or measure the current during start. Protection against water etc. etc. etc.

RC-Servos are controlled by a pulse-with-modulated signal.
most left position pulses of length 800-1000 microseconds most right position pulses with 2000 - 2400 microseconds. How far a servo can turn differs from product to product. What shortest / longest pulse-with-signal-length it can deal with differs from product to product too.

Some servos can turn mechanically a higher number of degrees than with the controlling signal turns them.
However building such a system means to examine and test all parts carefully and testing them to the limits in a way that does not damage them but still goes to the limits to see how does part behave in exceptional situations.

So please write what components do you already have and use the attachment-function to attach pictures.

About a beginner system for your son. Which Kit might be well suited depends on the interests of your son.
Is it purely programming so any PC with installed python will do. If it is about electronics too I would recommend a small and cheap arduino any Arduino clone will work just the same as an original arduino. Ora ESP32-board. ESP32s have bluetooth and WiFi onboard.
With a few clicks and inserting a "board manager URL" in the preferences of the Arduino-IDE ESP32s can be programmed just like Arduinos.

best regards Stefan

ok so ill look that up i saw a small kit not too expensive

might be good..

so ok i clicked the preview and seen the attachment i never clicked it as i didnt wanna loose what i had wrote.. had a few times page got erased i typed...

as for coding. i got something working but i come into a couple issues.
1.. the Servos i see are twiching how you stop it.. i tried not using 0 i tried 20 as a init state but still twitchs
2.. i noticed when i do say x=x+1 i can make the servo go a certain speed but if i do x=x-1 to go back it goes slower... i had to do x=x-10 using a 10 to be equal to a +1
so what i mean is

x=x+1 ( goes forward speed_
x=x-10 (goes the same speed as forward)
x=x-1 (goes slower then the forward speed)
why is that

next issue i found.. i tried a couple scenearios 1 was a LOW and HIGH on the switch this was to try to elimate the twitch
then i tried 2 wires from the switch.. so you only read HIGH to try to elimate the twitch no go..

but what i found is this code reads all of it.. and if i add'd a delay pf 10000 instead of 10... it hogs the system you can no longer click the other toggle switch it has to wait till the 10000 is done.. how can you do more then 1 at a time

so i had to keept is as A0 A1 for Switch 1 to only check HIGH not Low and A2 and A3 for switch 2 to Check for HIGH
as i found if it checks for Low it can get into potential endless loop if you set the Delay 10000 say
it will constantly see LOW and keep running 10000 delay...

hopefully you can run my project and see the twitch and its little messy i remmed out what i was tweaking with and then noticed the delay issue etc

as for coding. i got something working

Please post the code here, using code tags when you do, rather than expecting people to go to another site

By the way, the TinkerCad link has expired

Hi comet,

even if the testwindow contains just a single word you can click “preview” to add the attachment options.

have you read the switch/Button tutorial?
connecting switches and buttons: Gammon Forum : Electronics : Microprocessors : Switches tutorial

You will have a much faster progress in your project if you gain some basic knowledge about electronics
so please read it.

As already mentioned the TinkerCAD link expired. And I don’t have a tincercad acount.

Do you have a computer or laptop running windows or linux?
Programming will become much easier if you install the Arduino IDE 1.8.13.
Then you will be able to copy & paste your code into a forum-post with three mouse-clicks and four key-presses.

That’s the standard way of making code available for other users.
I will only comment on your code if your code is visible as code-section.
especially about the dleay(10000) thing.
there are very good solutions but I will only explain them if you post code in the standardway. Whci is:

Inside Arduino IDE
press Ctrl-T for auto-formatting your code
do a right-click and choose copy to forum

Then change back to your posting press Ctrl-V to paste the code into the posting.
After clicking on “post” the code will appear as a code-section.

If you changed something in the wiring. Add a new hand-drawing of your actual wiring.
Just writing about “one wire” two wire" has way too much room for mis-interpretation.

best regards Stefan

thats weird... it says 323 Hours left so cant be expired guesss they are glitched
so ill check that link out now then..
and i did download the arduino ide software i will install it now too
hope it all works the pics and 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
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 switch1,switch2,switch1a,switch2a;
  
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  
  switch1 == LOW;
  switch2 == LOW;
  switch1a == LOW;
  switch2a == LOW;

}

void loop()
{
//read the valvue of the 2 pins  Low or High
switch1 = digitalRead(A0);
switch2 = digitalRead(A1);
switch1a = digitalRead(A2);
switch2a = digitalRead(A3);  

  
//Switch (Open The Fuel Valve)  
if(!switch1 == 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(!switch1a == HIGH){
//switch1 == LOW;
	fuelangle = fuelangle -1;
	if (fuelangle < fuelstart){fuelangle = fuelstart;}
		fuelservo.write(fuelangle);
		delay(10);}  
  
//Switch (Set Choke to the Choke Pos)  
if(!switch2 == 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(!switch2a == HIGH){
// if(!switch2 == LOW){
//   switch2 == LOW;
	chokeangle = chokeangle -10;
	if (chokeangle < chokestart){chokeangle = chokestart;}
		chokeservo.write(chokeangle);
		delay(10);}  
  
  
}