I came up with the idea to make an elephant whose nose can swing and crown can move. I used a servo motor and solenoid individually for the elephant’s nose and crown. Once the device is connected to power, the crown will stretch forward and backward while the nose will start to swing from left to right and then left.
int sensor = A0; // the value of sensor int sensorVal; void setup() { // put your setup code here, to run once: pinMode(2, OUTPUT); // solenoid Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: sensorVal = analogRead(sensorVal); // the sensor Serial.println(sensorVal); if (sensorVal >= 1 && sensorVal <= 260) { digitalWrite(2, HIGH); delay(200); digitalWrite(2, LOW); delay(200); } else { digitalWrite(2, HIGH); delay(200); digitalWrite(2, LOW); delay(700); } delay(2); }