Can Someone check out this sketch and see if I am correct?

12 Volt input, 2 DC motors, Leds light when buttons send signal through to board. PINs send signal to motor controller and it drives the motors.

The code is something else entirely.

Thanks for your help. :slight_smile:

10K resistors

Checkout which sketch I don't see one ?

An image of a fritznuts thingy is not posted code.

It would be nice to see the well formatted code in code tags, not some graphic which cannot be loaded into a sketch for evaluation.

If using 10K resistors then you don’t really need the dimly lit LED when the button is pressed.

Example of well formatted code in code tags:

void fDoMoistureDetector( void * parameter )
  //wait for a mqtt connection
  while ( !MQTTclient.connected() )
    vTaskDelay( 250 );
  int      TimeToPublish = 5000000; //5000000uS
  int      TimeForADreading = 100 * 1000; // 100mS
  float    WetValue = 1.35f; // value found by putting sensor in water
  float    DryValue = 2.732f; // value of probe when held in air
  float    ADbits = 4095.0f;
  float    uPvolts = 3.3f;
  float    adcValue_b = 0.0f; //Jeanne's plant in yellow pot
  float    Range = DryValue - WetValue;
  float    RemainingMoisture = 100.0f; //prevents pump turn on during start up
  int      printCounts = 0;
  uint64_t TimePastKalman  = esp_timer_get_time(); // used by the Kalman filter UpdateProcessNoise, time since last kalman calculation
  uint64_t TimePastPublish = esp_timer_get_time(); // used by publish
  uint64_t TimeADreading   = esp_timer_get_time();
  TickType_t xLastWakeTime = xTaskGetTickCount();
  const TickType_t xFrequency = 10; //delay for 10mS
  SimpleKalmanFilter KF_ADC_b( 1.0f, 1.0f, .01f );
  for (;;)
    //read AD values every 100mS.
    if ( (esp_timer_get_time() - TimeADreading) >= TimeForADreading )
      adcValue_b = float( adc1_get_raw(ADC1_CHANNEL_3) ); //take a raw ADC reading
      adcValue_b = ( adcValue_b * uPvolts ) / ADbits; //calculate voltage
      KF_ADC_b.setProcessNoise( (esp_timer_get_time() - TimePastKalman) / 1000000.0f ); //get time, in microsecods, since last readings
      adcValue_b = KF_ADC_b.updateEstimate( adcValue_b ); // apply simple Kalman filter
      TimePastKalman = esp_timer_get_time(); // time of update complete
      RemainingMoisture = 100.0f * (1 - ((adcValue_b - WetValue) / (DryValue - WetValue))); //remaining moisture =  1-(xTarget - xMin) / (xMax - xMin) as a percentage of the sensor wet dry volatges
      TimeADreading = esp_timer_get_time();
    //read gpio 0 is water level good. Yes: OK to run pump : no pump off.   remaining moisture good, denergize water pump otherwise energize water pump.
    if ( gpio_get_level( GPIO_NUM_0 ) )
      if ( RemainingMoisture >= 40.0f ) {
      if ( RemainingMoisture <= 20.0f )
    } else {
      log_i( "water level bad " );
    if ( printCounts == 100 )
      log_i( "adcValue_b = %f remaining moisture %f%", adcValue_b, RemainingMoisture );
      printCounts = 0;
    // publish to MQTT every 5000000uS
    if ( (esp_timer_get_time() - TimePastPublish) >= TimeToPublish )
      //then publish
      xSemaphoreTake( sema_MQTT_KeepAlive, portMAX_DELAY ); // whiles MQTTlient.loop() is running no other mqtt operations should be in process
      MQTTclient.publish( topicRemainingMoisture_0, String(RemainingMoisture).c_str() );
      xSemaphoreGive( sema_MQTT_KeepAlive );
      TimePastPublish = esp_timer_get_time(); // get next publish time
    xLastWakeTime = xTaskGetTickCount();
    vTaskDelayUntil( &xLastWakeTime, xFrequency );
  vTaskDelete( NULL );
}// end fDoMoistureDetector()

The code doesn’t matter, that’s why it isn’t posted under the programming link

My question was about the wire configuration ... but never mind

****Please close this discussion ****

As shown, your switches/led in series with the wemos input will not work. The inputs of the wemos are floating (not good) unless the push button is pressed. The led will not light when pushbutton is pressed since its wired incorrectly and you’re trying to sink current through an input which does not work.

The cathode of the each led needs to be connected to gnd and the input pins of the wemos must be connected to junction of the switch and resistor. I don’t know if that work to hold the wemos input low, sinking current through the resistor and diode. Might work but it’s not ideal. You may need to add a 10k resistor from each input pin to ground to prevent a floating input level. If you get erroneous high levels without the button being pressed, that’s the problem and you’ll need the pull down resistors.

This is where Fritzing images fail miserably. They are not a schematic. The mistake would be obvious with a schematic. With Fritzing, you need to use a wall of words to explain any mistake. They just don’t work. A huge mistake that only slow down the learning process, wasting everyone’s time in the process.

If you want no further discussion on a topic, edit your original post and insert “closed” as the first word of the subject line. That’s your job, not the mods.

Time out. I just realized you’re using 5v supply on a device rated for only 3.3 volts input. Not good. That’s not going to work at all.

OK I've attached the new configuration. And thanks for the guidance on the forum guidelines.

Might work, it depends upon how you orient the pushbuttons. They will work two of the four ways the could be installed. But, you’re still putting 5 volts on a 3.3 volt input. It has been said the 8266 is 5v tolerant. No personal experience. How lucky do you feel?

Oh, and you also need pull down resistors on the inputs to prevent floating inputs. 10k, input pins to ground. Four places.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.