Good Day to you, Happy NEW YEAR..
Turn on-off? you mean like a manual flip type switch? I use opto22 ttl-transistor modules for the things around here, 5 volts in turns on a transistor or TRIAC type relay inside for 5 amps.. inputs are as simple, you plug a input module into the rack and when it see's voltage on the line side it sends a ttl logic voltage to your board.. one side logic, other side field wiring..
Sensing a load, well more thought and more description needed.
Last night, while watching tele I did this..
Code snipped, I hope I commented it well enough to follow..
************************************************************
/*
Modified to read a IRPD sensor, has a center detector, and a left and right LED transmitter, turn on
both, read for center location, left, then right LED's to set road map ahead reflection.
BUILD a binary truth table to direct the bot. 0,0,0 or 1,1,1 or??
12-27-13, added the SERVO point subroutine to hunt when the sensor changes, like a steer mode.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
#include <Servo.h>
Servo myservo; // create servo object to control a servo, maximum of eight ;
const int led = 13;
const int lftled = 36; //'turn on the enable left;
const int rtled = 40; // 'turn on the enable right;
const int Sens = 32; //'this is the input from the sensor detect;
int Radar ;
int VARR;
int pos = 0; // variable to store the servo position
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
pinMode(lftled,OUTPUT);
pinMode(rtled,OUTPUT);
pinMode(Sens,INPUT);
Serial.begin(19200);
myservo.attach(2); // attaches the servo on pin 2 to the servo object
}
// the loop routine runs over and over again forever:
void loop() {
Radar=0;
digitalWrite(led,HIGH); // turn the LED on HIGH is the voltage level
digitalWrite(lftled,HIGH);
delay(5);
// look to the sensor valve only left.
VARR = digitalRead(Sens); // set the variable equal to the IRPD output
if (VARR = HIGH) {
// add left bit:
(Radar = Radar + 1);
}
{
// turn on the right LED and add right Radar.
digitalWrite(lftled,HIGH);
digitalWrite(rtled,HIGH);
delay(5);
// look to the sensor valve only left.
VARR = digitalRead(Sens);
}
if (VARR == HIGH) {
// add middle bit:
(Radar = Radar + 2);
digitalWrite(lftled,LOW);
digitalWrite(rtled,HIGH);
delay(5);
}
// look to the sensor valve only left.
VARR = digitalRead(Sens);
if (VARR == HIGH) {
// add right bit
(Radar = Radar + 4);
// turn LED off
digitalWrite(led,LOW);
digitalWrite(lftled,LOW);
digitalWrite(rtled,LOW);
delay(5);
}
{
Serial.println(Radar);
delay(10); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(10); // wait for a second
(Radar = Radar * 24); // in steps of 1 degree
myservo.write(Radar); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}
}